local config = require('rustaceanvim.config.server')
local compat = require('rustaceanvim.compat')
describe('Decode rust-analyzer settings from json', function()
  local function expect_correct_loading(json_path)
    local settings = config.load_rust_analyzer_settings(json_path)
    assert.True(settings['rust-analyzer'].cargo.targetDir)
    assert.same({ 'leptosfmt', '--stdin', '--rustfmt' }, settings['rust-analyzer'].rustfmt.overrideCommand)
    assert.True(settings['rust-analyzer'].checkOnSave)
  end
  it('Fixture: rust-analyzer key', function()
    local json_path = compat.joinpath(vim.fn.getcwd(), 'spec', 'fixtures', 'rust-analyzer-json')
    expect_correct_loading(json_path)
  end)
  it('Fixture: top-level settings', function()
    local json_path = compat.joinpath(vim.fn.getcwd(), 'spec', 'fixtures', 'rust-analyzer-json-top-level')
    expect_correct_loading(json_path)
  end)
end)
